Skip to content

test(handlers): drive auth/cli_auth/magic_link to ≥95% coverage#157

Open
mastermanas805 wants to merge 2 commits into
masterfrom
coverage/api-handlers-auth-95
Open

test(handlers): drive auth/cli_auth/magic_link to ≥95% coverage#157
mastermanas805 wants to merge 2 commits into
masterfrom
coverage/api-handlers-auth-95

Conversation

@mastermanas805
Copy link
Copy Markdown
Member

Summary

  • Drives the auth handler files in internal/handlers to ≥95% statement coverage: auth.go 95.33%, cli_auth.go 95.56%, magic_link.go 95.15% (login/me/refresh/logout, OAuth GitHub/Google + browser callbacks, CLI device-flow, magic-link Start/Callback).
  • Adds behaviour-preserving source seams: OAuth provider URLs become test-repointable package vars (SetOAuthURLsForTest); PersistMagicLinkSendStatusForTest re-exports the unexported persist helper to reach its log-and-swallow error arms.
  • New branch coverage via deterministic fault injection — isolated per-test DB (DROP TABLE / CHECK constraint), a concurrent single-use consume race for the !consumed branch, and direct helper calls: OAuth browser-callback exchange/userinfo failures, find-or-create new-user markEmailVerified + link errors, FindOrCreateUserByEmail empty-local-part teamName fallback, magic-link persist-status both error arms.

The 3 residual uncovered magic_link.go blocks are genuinely unreachable without rand/redis-internal fault injection (pipeline Exec surfaces the command error before Result() is read; rand.Read never fails; HMAC sign never errors on a valid []byte key) and are documented inline.

Test plan

  • Targeted suite green, -p 1: go test ./internal/handlers -run 'TestAuth|TestCLI|TestMagicLink|TestLogin|TestRefresh|TestLogout' -count=1 -p 1
  • Per-file coverage ≥95% confirmed via the coverprofile
  • No auth/cli/magic_link tests regress; the only full-package flakes observed are the pre-existing shared-Redis-counter / pg_class migration-race artifacts in unrelated billing/db/nosql/storage/deploy tests (pass cleanly against a fresh Redis, which CI uses)
  • CI gate (make gate) green

mastermanas805 and others added 2 commits May 22, 2026 09:17
Covers the login/me/refresh/logout, OAuth (GitHub/Google + browser
callbacks), CLI device-flow, and magic-link Start/Callback paths.

Adds source seams that keep behaviour unchanged in prod:
- OAuth provider endpoint URLs become package vars repointable at an
  httptest server (SetOAuthURLsForTest) so the full exchange →
  find-or-create-user → mint-JWT path runs against a fake provider.
- PersistMagicLinkSendStatusForTest re-exports the unexported persist
  helper so its two log-and-swallow error branches are reachable.

New error/branch coverage via deterministic fault injection (isolated
per-test DB with DROP TABLE / CHECK constraint tricks, a concurrent
single-use consume race, and direct helper calls):
- GitHub/Google browser-callback exchange + userinfo failures
- findOrCreateUserGitHub/Google new-user markEmailVerified + link errors
- FindOrCreateUserByEmail empty-local-part teamName fallback
- magic-link persist-status both error arms + the consume-race
  (!consumed) branch

Final per-file: auth.go 95.33%, cli_auth.go 95.56%, magic_link.go 95.15%.
The 3 residual uncovered magic_link.go blocks are genuinely unreachable
without rand/redis-internal fault injection (pipe.Exec returns the cmd
error before Result is read; rand.Read never fails; HMAC sign never
errors on a valid []byte key) and are documented inline.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant